package cn.wen.eeayjoke.view;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import butterknife.BindView;
import cn.wen.eeayjoke.R;
import cn.wen.eeayjoke.utils.ArgbUtil;

/**
 * 首页的标题
 */

public class HomeTitleHolder extends ViewHolder {
    public static final int defColor = Color.parseColor("#FFFFFF");
    @BindView(R.id.iv_home_scan)
    ImageView mIvScan;
    @BindView(R.id.iv_home_msg)
    ImageView mIvMsg;
    @BindView(R.id.ll_home_title_content)
    LinearLayout mLLTitleContent;
    @BindView(R.id.fl_home_title_root)
    View mFLTitleRoot;
    @BindView(R.id.et_home_search)
    EditText mEtSearch;
    @BindView(R.id.v_line)
    View mViewLine;
    private int defAlpha;


    @Override
    protected Object getLayout() {
        return R.layout.layout_home_title;
    }

    public HomeTitleHolder(Activity activity, ViewGroup parent) {
        super(activity, parent);
    }

    public HomeTitleHolder(Activity activity) {
        super(activity);
    }

    @Override
    protected void initView(View view) {
        mLLTitleContent.getBackground().setAlpha(0);
        mFLTitleRoot.getBackground().setAlpha(0);
        defAlpha = (int) (0.4 * 255);
        mEtSearch.getBackground().setAlpha(defAlpha);
        mIvScan.setColorFilter(defColor);
        mIvMsg.setColorFilter(defColor);
        mViewLine.setVisibility(View.GONE);
    }



    public View getFLTitleRoot() {
        return mFLTitleRoot;
    }

    public void change(float alpha) {
        mViewLine.setVisibility(View.GONE);
        if (alpha < 0) {
            alpha = 0;
        } else if (alpha > 1) {
            alpha = 1;
            mViewLine.setVisibility(View.VISIBLE);
        }
        int bgAlpha = (int) (alpha * 255);
        mLLTitleContent.getBackground().setAlpha(bgAlpha);
        mFLTitleRoot.getBackground().setAlpha(bgAlpha);
        if (bgAlpha > defAlpha) {
            mEtSearch.getBackground().setAlpha(bgAlpha);
        } else {
            mEtSearch.getBackground().setAlpha(defAlpha);
        }
        int filterColor = ArgbUtil.getDefault().evaluate(alpha, 0xffffffff, 0Xff5f646e);
        mIvScan.setColorFilter(filterColor);
        mIvMsg.setColorFilter(filterColor);
        mEtSearch.setHintTextColor(filterColor);
        mEtSearch.setTextColor(filterColor);
    }
}
